package com.itheima.controller;

import com.itheima.entity.Result;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("getUserName")
    public Result findUserName(){

       User user =  (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();

       String name =user.getUsername();

       if(name!=null){
           return new Result(true,"查询成功",name);
       }else{
           return new Result(false,"查询失败");
       }
    }
}
